package com.mentalsurvey.controller;

import com.mentalsurvey.dto.QuestionBatchCreateDTO;
import com.mentalsurvey.entity.Question;
import com.mentalsurvey.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author vito
 * @version 1.0
 */
@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    /**
     * 批量创建题目
     */
    @PostMapping("/batchCreate")
    public String batchCreate(@RequestBody QuestionBatchCreateDTO dto) {
        try {
            questionService.batchCreate(dto);
            return "题目创建成功";
        } catch (IllegalArgumentException e) {
            return e.getMessage();
        }
    }

    /**
     * 根据试卷ID查询题目列表
     *
     * @param paperId 试卷ID
     * @return 题目列表
     */
    @GetMapping("/listByPaperId")
    public List<Question> getQuestionsByPaperId(@RequestParam Integer paperId) {
        return questionService.getQuestionsByPaperId(paperId);
    }
}
